package com.example.mydemo103.ui.home;

import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.mydemo103.R;
import com.example.mydemo103.ui.BookAllActivity;
import com.example.mydemo103.ui.BookSerchActivity;
import com.example.mydemo103.ui.BookdetailsActivity;


public class HomeFragment extends Fragment implements View.OnClickListener {
    @Nullable
    private TextView address, mainmore1,mainmore2,mainmore3,mainmore4,mainmore5,class1,class2,class3,class4;
    private EditText serchbook;
    private ImageView shopcar;
    private RelativeLayout TJbook1,TJbook2;

//    int[] image={R.drawable.photo,R.drawable.flickr,R.drawable.folder,R.drawable.game,
//            R.drawable.gtalk,R.drawable.movie,R.drawable.music,R.drawable.wheather};
//    String[] text={"第一项","第二项","第三项","第四项","第五项","第六项","第七项","第八项"};
//    private GridView gridView;
//    ArrayList<HashMap<String,Object>> datas=new ArrayList<HashMap<String,Object>>();
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_home,container,false);
        address=view.findViewById(R.id.address);
        mainmore1=view.findViewById(R.id.mainmore1);
        mainmore2=view.findViewById(R.id.mainmore2);
        mainmore3=view.findViewById(R.id.mainmore3);
        mainmore4=view.findViewById(R.id.mainmore4);
        mainmore5=view.findViewById(R.id.mainmore5);
        class1=view.findViewById(R.id.class1);
        class2=view.findViewById(R.id.class2);
        class3=view.findViewById(R.id.class3);
        class4=view.findViewById(R.id.class4);
        serchbook=view.findViewById(R.id.searchforbook);
        shopcar=view.findViewById(R.id.shopcar);
        TJbook1=view.findViewById(R.id.TJbook1);
        TJbook2=view.findViewById(R.id.TJbook2);


        shopcar.setOnClickListener(this);
        class1.setOnClickListener(this);
        class2.setOnClickListener(this);
        class3.setOnClickListener(this);
        class4.setOnClickListener(this);
        serchbook.setOnClickListener(this);
        TJbook1.setOnClickListener(this);
        TJbook2.setOnClickListener(this);
        mainmore1.setOnClickListener(this);
        mainmore2.setOnClickListener(this);
        mainmore3.setOnClickListener(this);
        mainmore4.setOnClickListener(this);
        mainmore5.setOnClickListener(this);

//        shopcar.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent=new Intent(getActivity(), BookdetailsActivity.class);
//                startActivity(intent);
//            }
//        });

        Drawable drawablebyaddress=getResources().getDrawable(R.drawable.address);
        drawablebyaddress.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        address.setCompoundDrawables(drawablebyaddress,null,null,null);

        Drawable drawablebymainmore1=getResources().getDrawable(R.drawable.right);
        drawablebymainmore1.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        mainmore1.setCompoundDrawables(null,null,drawablebymainmore1,null);
        mainmore2.setCompoundDrawables(null,null,drawablebymainmore1,null);
        mainmore3.setCompoundDrawables(null,null,drawablebymainmore1,null);
        mainmore4.setCompoundDrawables(null,null,drawablebymainmore1,null);
        mainmore5.setCompoundDrawables(null,null,drawablebymainmore1,null);

        Drawable drawablebyclass=getResources().getDrawable(R.drawable.classimage);
        drawablebyclass.setBounds(0,0,100,80);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        class1.setCompoundDrawables(null,drawablebyclass,null,null);
        class2.setCompoundDrawables(null,drawablebyclass,null,null);
        class3.setCompoundDrawables(null,drawablebyclass,null,null);
        class4.setCompoundDrawables(null,drawablebyclass,null,null);

        Drawable drawablebysearch=getResources().getDrawable(R.drawable.search);
        drawablebysearch.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        serchbook.setCompoundDrawables(drawablebysearch,null,null,null);

        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.shopcar:
                Intent intent=new Intent(getActivity(), BookdetailsActivity.class);
                startActivity(intent);
                break;
            case R.id.class1:
                Intent intentbyclass1=new Intent(getActivity(), BookAllActivity.class);
                startActivity(intentbyclass1);
                break;
            case R.id.class2:
                Intent intentbyclass2=new Intent(getActivity(), BookAllActivity.class);
                startActivity(intentbyclass2);
                break;
            case R.id.class3:
                Intent intentbyclass3=new Intent(getActivity(), BookAllActivity.class);
                startActivity(intentbyclass3);
                break;
            case R.id.class4:
                Intent intentbyclass4=new Intent(getActivity(), BookAllActivity.class);
                startActivity(intentbyclass4);
                break;
            case R.id.mainmore1:
                Intent mainmore1=new Intent(getActivity(), BookAllActivity.class);
                startActivity(mainmore1);
                break;
            case R.id.mainmore2:
                Intent mainmore2=new Intent(getActivity(), BookAllActivity.class);
                startActivity(mainmore2);
                break;
            case R.id.mainmore3:
                Intent mainmore3=new Intent(getActivity(), BookAllActivity.class);
                startActivity(mainmore3);
                break;
            case R.id.mainmore4:
                Intent mainmore4=new Intent(getActivity(), BookAllActivity.class);
                startActivity(mainmore4);
                break;
            case R.id.mainmore5:
                Intent mainmore5=new Intent(getActivity(), BookAllActivity.class);
                startActivity(mainmore5);
                break;
            case R.id.TJbook1:
                Intent TJbook1=new Intent(getActivity(), BookdetailsActivity.class);
                startActivity(TJbook1);
                break;
            case R.id.TJbook2:
                Intent TJbook2=new Intent(getActivity(), BookdetailsActivity.class);
                startActivity(TJbook2);
                break;
            case R.id.searchforbook:
                Intent intentbyserchforbook=new Intent(getActivity(), BookSerchActivity.class);

                intentbyserchforbook.putExtra("bookname",serchbook.getText().toString());
                startActivity(intentbyserchforbook);
                break;
        }
    }


//        simpleadapter简单列表
//        gridView=view.findViewById(R.id.gridviewone);
//        for(int i=0;i<image.length;i++){
//            HashMap<String,Object> map=new HashMap<String,Object>();
//            map.put("itemsimage",image[i]);
//            map.put("itemstext",text[i]);
//            datas.add(map);
//        }
//        SimpleAdapter simpleAdapter=new SimpleAdapter(
//                getActivity(),
//                datas,
//                R.layout.gridview,
//                new String[]{"itemsimage","itemstext"},
//                new int[]{R.id.gridviewimage,R.id.gridviewtext});
//        gridView.setAdapter(simpleAdapter);
//         gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//             @Override
//             public void onItemClick(AdapterView<?> adapterView, View view, int i , long l) {
//                switch (i){
//                    case 0:
//                        Intent intent=new Intent(getActivity(), LgoinActivity.class);
//                        startActivity(intent);
//                    case 1:
//
//
//
//                }
//                 System.out.println(datas.get(i).get("itemstext"));
//             }
//
//
//         });
}